package com.zhiyueshufang.fragment

import android.content.Context
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import com.zhiyueshufang.R
import com.zhiyueshufang.activity.HomeActivity
import com.zhiyueshufang.databinding.FragmentIndexBinding

class IndexFragment : Fragment() {

    lateinit var binding: FragmentIndexBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentIndexBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun onResume() {
        super.onResume()
        setTopAreaBackgroundColor(R.color.purple)
    }


    /**
     * 设置顶部背景颜色
     */
    private fun setTopAreaBackgroundColor(@ColorRes colorId: Int) {
        setStatusBarColor(colorId)
        binding.rlHomeTop.setBackgroundColor(
            ContextCompat.getColor(activity as Context, colorId)
        )
        binding.rlHomeTopShape.setBackgroundColor(
            ContextCompat.getColor(activity as Context, colorId)
        )
    }

    /**
     * 设置外部状态栏颜色
     */
    private fun setStatusBarColor(@ColorRes id: Int) {
        var parentActivity = activity as HomeActivity
        parentActivity.setStatusBarColor(id)
    }
}